<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sign an S/MIME message</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-pkcs7-encrypt.html">openssl_pkcs7_encrypt</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.openssl-pkcs7-verify.html">openssl_pkcs7_verify</a></div>
 <div class="up"><a href="ref.openssl.html">OpenSSL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.openssl-pkcs7-sign" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_pkcs7_sign</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5)</p><p class="refpurpose"><span class="refname">openssl_pkcs7_sign</span> &mdash; <span class="dc-title">Sign an S/MIME message</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-pkcs7-sign-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>openssl_pkcs7_sign</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$infilename</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$outfilename</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$signcert</code></span>
   , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$privkey</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$headers</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = PKCS7_DETACHED</span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$extracerts</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>openssl_pkcs7_sign()</strong></span> takes the contents of the file
   named <em><code class="parameter">infilename</code></em> and signs them using the
   certificate and its matching private key specified by
   <em><code class="parameter">signcert</code></em> and <em><code class="parameter">privkey</code></em>
   parameters.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-pkcs7-sign-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">infilename</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">outfilename</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">signcert</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">privkey</code></em></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">headers</code></em></dt>

     <dd>

      <p class="para">
       <em><code class="parameter">headers</code></em> is an array of headers that
       will be prepended to the data after it has been signed (see
       <span class="function"><a href="function.openssl-pkcs7-encrypt.html" class="function">openssl_pkcs7_encrypt()</a></span> for more information about
       the format of this parameter).
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">flags</code></em></dt>

     <dd>

      <p class="para">
       <em><code class="parameter">flags</code></em> can be used to alter the output - see <a href="openssl.pkcs7.flags.html" class="link">PKCS7 constants</a>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">extracerts</code></em></dt>

     <dd>

      <p class="para">
       <em><code class="parameter">extracerts</code></em> specifies the name of a file containing
       a bunch of extra certificates to include in the signature which can for
       example be used to help the recipient to verify the certificate that you used.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-pkcs7-sign-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-pkcs7-sign-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-841">
    <p><strong>Example #1 <span class="function"><strong>openssl_pkcs7_sign()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;the&nbsp;message&nbsp;you&nbsp;want&nbsp;to&nbsp;sign&nbsp;so&nbsp;that&nbsp;recipient&nbsp;can&nbsp;be&nbsp;sure&nbsp;it&nbsp;was&nbsp;you&nbsp;that<br />//&nbsp;sent&nbsp;it<br /></span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOD<br /></span><span style="color: #DD0000"><br />You&nbsp;have&nbsp;my&nbsp;authorization&nbsp;to&nbsp;spend&nbsp;$10,000&nbsp;on&nbsp;dinner&nbsp;expenses.<br /><br />The&nbsp;CEO<br /></span><span style="color: #007700">EOD;<br /></span><span style="color: #FF8000">//&nbsp;save&nbsp;message&nbsp;to&nbsp;file<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"msg.txt"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;encrypt&nbsp;it<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">openssl_pkcs7_sign</span><span style="color: #007700">(</span><span style="color: #DD0000">"msg.txt"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"signed.txt"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mycert.pem"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">"file://mycert.pem"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mypassphrase"</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">"To"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"joes@example.com"</span><span style="color: #007700">,&nbsp;</span><span style="color: #FF8000">//&nbsp;keyed&nbsp;syntax<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"From:&nbsp;HQ&nbsp;&lt;ceo@example.com&gt;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #FF8000">//&nbsp;indexed&nbsp;syntax<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"Subject"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Eyes&nbsp;only"</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;message&nbsp;signed&nbsp;-&nbsp;send&nbsp;it!<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">"sendmail_path"</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"&nbsp;&lt;&nbsp;signed.txt"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.openssl-pkcs7-encrypt.html">openssl_pkcs7_encrypt</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.openssl-pkcs7-verify.html">openssl_pkcs7_verify</a></div>
 <div class="up"><a href="ref.openssl.html">OpenSSL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
